package com.linran.controller;

import com.alibaba.fastjson.JSONObject;
import com.linran.constant.Sex;
import com.linran.domain.User;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
public class EnumConvertController {

    @RequestMapping("/user")
    public Object userPost(@RequestBody User user){
        Optional.ofNullable(user).ifPresent(u-> System.out.println(JSONObject.toJSONString(u)));
        return "接收数据："+Optional.ofNullable(user).map(JSONObject::toJSONString).orElse("null");
    }

    @GetMapping("/enum/{value}")
    public Object userPost(@PathVariable("value") Sex sex){
        System.out.println(sex);
        return "enum:"+sex.name();
    }
}
